package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.AggSumDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.FormDataSummaryDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.AggSumVO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.contract.pojo.dto.QuotationUpdateBatchDTO;
import com.xbongbong.pro.customer.pojo.dto.ChangeStatusDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerRestoreBatchDTO;
import com.xbongbong.pro.defaultData.pojo.dto.DefaultDataDTO;
import com.xbongbong.pro.defaultData.pojo.vo.DefaultDataVO;
import com.xbongbong.pro.detailtab.vo.DetailTabGetVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.pro.quatation.pojo.dto.QuotationEditAttrUpdateDTO;
import com.xbongbong.pro.quatation.pojo.dto.QuotationGetDTO;
import com.xbongbong.pro.quatation.pojo.dto.QuotationHistoryDTO;
import com.xbongbong.pro.quatation.pojo.vo.QuotationGetVO;
import com.xbongbong.pro.warehouse.pojo.vo.QuotationDeleteBatchVO;
import com.xbongbong.pro.workorder.pojo.dto.QuotationDeleteBatchDTO;
import com.xbongbong.saas.domain.entity.QuotationProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/8/12 19:58
 * @since v1.0
 */
public interface QuotationService {

    /**
     * 报价单保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-08-12 19:58
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 报价单保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-08-12 19:58
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;


    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-08-12 19:58
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;


    /**
     * Description: 生成新版本
     * @param quotationGetDTO
     * @return QuotationAddVO
     * @throws XbbException
     * @author 刘阳
     * @date 2019/8/16 10:12 PM
     * @since v1.0
     */
    QuotationGetVO getNewVersion(QuotationGetDTO quotationGetDTO) throws XbbException;

    /**
     * Description: 历史版本
     * @param quotationHistoryDTO
     * @return DetailTabGetVO
     * @throws XbbException
     * @author 刘阳
     * @date 2019/8/14 7:41 PM
     * @since v1.0
     */
    DetailTabGetVO getHistory(QuotationHistoryDTO quotationHistoryDTO) throws XbbException;
    /**
     * 格式化产品，显示给前端
     * @param dataList 实体数据
     * @param saasAnalysisDataDTO 数据解析DTO
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-16 11:08
     */
    void formatProduct4Show(JSONObject dataList, SaasAnalysisDataDTO saasAnalysisDataDTO) throws XbbException;

    /**
     * Description: 批量删除报价单
     * @param quotationDeleteBatchDTO
     * @return com.xbongbong.pro.workorder.pojo.vo.WorkOrderDeleteBatchVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-16 21:27
     */
     QuotationDeleteBatchVO deleteBatch(QuotationDeleteBatchDTO quotationDeleteBatchDTO) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities 业务实体集合
     * @param totalCount 总数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-16 21:27
     */
    ListAppVO formatQuotationAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * Description: 关联新建时格式化解释
     * @param handlerExplainInLinkItemDTO
     * @return void
     * @throws XbbException XbbException
     * @author 刘阳
     * @date 2019/8/20 7:35 PM
     * @since v1.0
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 获取报价单关联产品
     *
     * @param businessProductListDTO
     * @return BusinessProductListVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-21 14:34
     */
//    BusinessProductListVO getQuotationProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * 修改报价单状态
     *
     * @param changeStatusDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-21 15:13
     */
    BaseVO changeStatus(ChangeStatusDTO changeStatusDTO) throws XbbException;

    /**
     * 格式化导出数据
     *
     * @param paasFormDataESList 数据
     * @param formDataListDTO 入参
     * @param fieldAttrList 解释
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * Description: 格式化导出excelvalue
     * @param importFormDataDTO 入参
     * @param titlePojoList 标题
     * @param rowGroupPojo 组
     * @param fieldAttrList 解释
     * @return FormDataAddDTO
     * @author 刘阳
     * @date 2019/8/21 7:47 PM
     * @since v1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;
    /**
     * 将报价单的某些值作为别的业务保存时的默认值
     *
     * @param defaultDataDTO
     * @param explainMap
     * @param quotationEntity
     * @throws
     * @author long.rao
     * @date 2019-10-09 10:46
     */
    DefaultDataVO getQuotationDefault(DefaultDataDTO defaultDataDTO, Map<String, FieldAttrEntity> explainMap, PaasFormDataEntityExt quotationEntity) throws XbbException;

    /**
     * 报价单产品查询
     *
     * @param corpid     公司id
     * @param customerId 客户id
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return java.util.Set<java.lang.Long>
     * @throws XbbException findByPage会出现异常
     * @author 徐俊杰
     * @date 2019/8/29 19:07
     * @since v1.0
     */
    Set<Long> customerQuotation(String corpid, Long customerId, Long startTime, Long endTime) throws XbbException;

    /**
     * 报价单趋势查询
     *
     * @param corpid 公司id
     * @param customerId 客户id
     * @return java.util.List<com.xbongbong.paas.domain.entity.PaasFormDataEntity>
     * @throws XbbException findByPage会出现异常
     * @author 徐俊杰
     * @date 2019/8/30 13:36
     * @since v1.0
     */
    List<PaasFormDataEntity> customerQuotationTrend(String corpid, Long customerId, Long startTime, Long endTime) throws XbbException;

    /**
     * Description: 通过客户id获取报价单
     * @param  corpid       公司id
     * @param  customerId   客户id
     * @return java.util.List<com.xbongbong.paas.domain.entity.PaasFormDataEntity>
     * @author 刘阳
     * @date 2019/9/4 10:20 AM
     * @since v1.0
     */
    List<PaasFormDataEntityExt> getQuotationEsDataListByCustomerId(String corpid, Long customerId) throws XbbException;

    /**
     * 汇总报价单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-09-09 15:04
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * Description: 一致性同步报价单数据
     * @param corpid 公司id
     * @param linkId 关联的id
     * @param linkName 需要修改的名称
     * @param linkAttr 需要修改的attr字段
     * @param linkNameAttr 需要修改的字段名称
     * @author long.rao
     * @date 2019-09-10 15:29
     */
    void dataConsistencyUpdate(String corpid, Long linkId, String linkName, String linkAttr, String linkNameAttr) throws XbbException;

    /**
     * 批量编辑
     *
     * @param quotationUpdateBatchDTO
     * @throws
     * @author long.rao
     * @date 2019-09-10 15:47
     */
    BaseVO updateBatch(QuotationUpdateBatchDTO quotationUpdateBatchDTO) throws XbbException;

    /**
     * 更新回滚
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 还原数据
     * @author xingxing.xiao
     */
    void restoreBatch(String corpid, Map<Long, Long> customerUpdateTimeMap, CustomerRestoreBatchDTO customerRestoreBatchDTO) throws XbbException;

    /**
     * 批量编辑
     * @author long.rao
     * @date 2019-10-17 10:01
     * @param quotationEditAttrUpdateDTO
     * @return BaseVO
     * @throws XbbException 业务异常
     */
    BaseVO batchEditAttr(QuotationEditAttrUpdateDTO quotationEditAttrUpdateDTO) throws XbbException;
    /**
     * 计算报价单毛利率汇总
     * @param numCountList
     * @param formDataSummaryDTO
     * @param aggAvgFieldList
     * @return
     * @throws XbbException
     * @author long.rao
     * @date 2019-10-25 16:05
     */
    List<AggSumVO> aggAvgByField(List<AggSumVO> numCountList, FormDataSummaryDTO formDataSummaryDTO, List<AggSumDTO> aggAvgFieldList, NativeSearchQuery searchQuery) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    void formatProduct4Show3(List<QuotationProductEntity> quotationProductEntityList, JSONObject productData, UpdateDataTypeEnum linkAdd, String corpid) throws XbbException;

    JSONObject formatSingleProduct(QuotationProductEntity entity);
    /**
     * Description: 获取报价单名称集合
     * @param handoverIdSet
     * @param corpid
     * @author 刘阳
     * @date 2020/1/8 2:41 PM
     * @since v1.0
     */
    Map<Long, String> getQuotationNameMap(List<Long> handoverIdSet, String corpid) throws XbbException;

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
